<!-- Github: https://github.com/lesca/anki/ -->

<div style="display: flex;" class="tags">
  <div style="flex-grow: 1;"></div>
  <div style="flex-grow: 1;" align="right">{{#Tags}}标签：{{/Tags}}{{^Tags}}无标签{{/Tags}}</div>
  <div style="flex-grow: 3;" align="left">{{Tags}}</div>
  <div style="flex-grow: 3;" align="right">{{Deck}}</div>
</div>

<div class="section">
  <div id="front" class="items">{{type:单词}}</div>
  <hr>
  <div id="sound" class="items">{{#发音}}{{发音}}{{/发音}}
    {{^发音}}[sound:https://dict.youdao.com/dictvoice?audio={{text:单词}}&type=1]{{/发音}}</div>
  <div id="phonetic" class="items">{{#音标}}{{音标}}{{/音标}}
    {{^音标}}<div id="phonetic_symobls"></div>{{/音标}}
  </div>
  <hr>
  <div id="def" class="items">{{释义}}</div>
</div>

{{#例句}}
<div class="section">
  <hr>
  <div id="sentence" class="items">{{例句}}</div>
</div>
{{/例句}}

{{#注释}}
<div class="section">
  <hr>
  <div id="note" class="items">{{注释}}</div>
</div>
{{/注释}}

<script type="text/javascript">
  function getPhoneticSymbols(word) {
    cors_proxy = "https://cors.silkdiy.cn"
    fetch(`${cors_proxy}/https://dict.youdao.com/jsonapi_s?q=${word}&le=en&t=2&client=web&sign=30ac8a1fffc5c066d343a8eb2ef8572e&keyfrom=webdict`)
      .then((response) => { return response.json() })
      .catch(error => console.error('Error:', error))
      .then(response => {
        // get
        phoneticSymbols = {
          "ukphone": response.simple.word[0].ukphone,
          "usphone": response.simple.word[0].usphone
        };
        // console.log(phoneticSymbols)
        // generate html
        phonetic_html = ""
        if (phoneticSymbols.ukphone) {
          phonetic_html += `英 /${phoneticSymbols.ukphone}/`
        }
        if (phoneticSymbols.usphone) {
          if (phonetic_html) {
            phonetic_html += `<br>美 /${phoneticSymbols.usphone}/`
          } else {
            phonetic_html += `美 /${phoneticSymbols.usphone}/`
          }
        }
        // replace
        var phonetic_symobls = document.querySelector("#phonetic_symobls");
        phonetic_symobls.innerHTML = phonetic_html
      });
  }
  getPhoneticSymbols("{{text:单词}}")
</script>